package com.itheima.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.Member;
import com.itheima.pojo.Order;
import com.itheima.service.OrderSettingListService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/orderSettingList")
public class OrderSettingListController {
    @Reference
    private OrderSettingListService orderSettingListService;

    @RequestMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
        return orderSettingListService.pageQuery(queryPageBean);
    }

    @RequestMapping("/add")
    public Result add(@RequestBody Map map, Integer setmealId){
        try{
            Result result = orderSettingListService.add(map, setmealId);
            if (result.isFlag() == true){
                return new Result(true,MessageConstant.ORDERSETTING_SUCCESS);//新增成功
            }else {
                return new Result(false, MessageConstant.ORDERSETTING_FAIL);//新增失败
            }
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false, MessageConstant.ORDERSETTING_FAIL);//新增失败
        }
    }

    @RequestMapping("/startOrder")
    public Result startOrder(Integer member_id,Integer setmeal_id){
        try {
            orderSettingListService.startOrder(member_id,setmeal_id);
            return new Result(true,MessageConstant.START_ORDER_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,MessageConstant.START_ORDER_FAIL);
        }
    }
        //取消预约
    @RequestMapping("/cancelOrder")
    public Result cancelOrder(Integer member_id,Integer setmeal_id){
        try {
            orderSettingListService.cancelOrder(member_id,setmeal_id);
            return new Result(true,MessageConstant.CANCEL_ORDER_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,MessageConstant.CANCEL_ORDER_FAIL);
        }
    }
}
